//
//  JANetworkTool.m
//  网易新闻
//
//  Created by Arvin on 17/3/19.
//  Copyright © 2017年 Arvin. All rights reserved.
//

#import "JANetworkTool.h"

@implementation JANetworkTool

+(instancetype)sharedTool;
{
    static JANetworkTool *tool = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        tool = [[JANetworkTool alloc]initWithBaseURL:nil];
    });
    return tool;
}

//网络中间层
-(void)reqeusWith: (NSString *)url
           method: (NSString *)method
       parameters: (NSDictionary *)parameters
         callBack: (void(^)(id))callBack{
    
    //调用AFN发起GET请求
    if([method isEqualToString:@"GET"]){
        [self GET:url parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            callBack(responseObject);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            NSLog(@"%@",error);
            callBack(nil);
        }];
    }
    
    //调用AFN发起POST请求
    if([method isEqualToString:@"POST"])
    {
        [self POST:url parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            callBack(responseObject);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            NSLog(@"%@",error);
            callBack(nil);
        }];
    }
    
}



@end
